package com.leo;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

/**
 * @ClassName PropertyChangeSupportDemo
 * @Description 事件绑定
 * @Author wangss
 * @date 2020.05.27 11:30
 * @Version 1.0
 */
public class PropertyChangeSupportDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane anchorPane = new AnchorPane();
        anchorPane.setStyle("-fx-background-color: #e7eeea");
        Scene scene = new Scene(anchorPane);

        Student s1 = new Student("wangss", 12, 22);

        Button button = new Button("修改");

        anchorPane.getChildren().addAll(button);

        primaryStage.setScene(scene);
        primaryStage.setTitle("spinner");
        primaryStage.setWidth(625d);
        primaryStage.setHeight(500d);
        primaryStage.setResizable(false);
        primaryStage.show();

        s1.pc.addPropertyChangeListener(new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                System.out.println("oldValue = " + evt.getOldValue());
                System.out.println("newValue = " + evt.getNewValue());
            }
        });

        s1.pc.addPropertyChangeListener("setName_pc", new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                System.out.println("oldValue = " + evt.getOldValue());
                System.out.println("newValue = " + evt.getNewValue());
            }
        });

        button.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                s1.setName("123");
            }
        });
    }
}
